//
//  RootViewController.m
//  UI大结局_消息通知
//
//  Created by dllo on 15/12/10.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "SecondViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"天王盖地虎" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"小鸡炖蘑菇" object:nil];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.navigationItem.title = @"第一页";
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(rightAction)];

    // 注册消息, 以及接收到消息后的处理方式和暗号
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction) name:@"天王盖地虎" object:nil];
    
    // 带参数的消息通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationChickAction:) name:@"小鸡炖蘑菇" object:nil];
    
}

- (void)notificationChickAction:(id)sender
{
    UIColor *color = (UIColor *)[sender object];
    self.view.backgroundColor = color;
}

- (void)notificationAction
{
    self.view.backgroundColor = [UIColor greenColor];
}

- (void)rightAction
{
    SecondViewController *secondVC = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:secondVC animated:YES];
    [secondVC release];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
